import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-10-08
 * Time: 12:34
 */
public class Combine {
    List<List<Integer>> ret;
    List<Integer> path;
    int _k;

    public List<List<Integer>> combine(int n, int k) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        _k = k;
        combine_dfs(n, 1);
        return ret;
    }

    private void combine_dfs(int n, int pos) {
        if (_k == path.size()) {
            ret.add(new ArrayList<>(path));
            return;
        }
        for (int i = pos; i < n + 1; i++) {
            path.add(i);
            combine_dfs(n, i + 1);
            path.remove(path.size() - 1);
        }
    }
}
